package com.cloudkinto.controller.job;


import com.cloudkinto.common.annotations.UserSessionRequired;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cloudkinto.service.job.AsyncJobService;

import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;

import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;

import java.util.HashMap;
import java.util.Map;

import com.cloudkinto.base.BaseController;

/**
 * <p>
 * 异步任务中心任务表 前端控制器
 * </p>
 * @author long
 * @since 2025-06-23
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "异步任务中心任务表模块")
@RequestMapping("/api/admin/AsyncJob")
public class AsyncJobController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(AsyncJobController.class);

    private final AsyncJobService service;



    @UserSessionRequired
    @GetMapping("/platformOrderlistPage")
    @ApiOperation(value = "导出任务表查询（分页）-平台订单", notes = "异步任务中心任务表查询（分页）")
    public PageResult platformOrderListPage(HttpServletRequest request){
        Long companyId = getCompanyId();

        Map<String, String> map = new HashMap<>();
        String keyword = request.getParameter("keyword");
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("keyword", keyword);
        map.put("current", current);
        map.put("pageSize", size);
        if (companyId != null) {
            map.put("companyId", companyId.toString());
        }
        map.put("beginTime", request.getParameter("beginTime"));
        map.put("endTime", request.getParameter("endTime"));
        map.put("jobType", "EXPORT_PLATFORM_ORDER");
        return service.getListPage(map);
    }

    @UserSessionRequired
    @GetMapping("/stockToPlatformListPage")
    @ApiOperation(value = "库存回传记录（分页）", notes = "库存回传记录（分页）")
    public PageResult stockToPlatformListPage(HttpServletRequest request){
        Long companyId = getCompanyId();

        Map<String, String> map = new HashMap<>();
        String keyword = request.getParameter("keyword");
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        String storeId = request.getParameter("storeId");

        map.put("keyword", keyword);
        map.put("current", current);
        map.put("pageSize", size);
        if (companyId != null) {
            map.put("companyId", companyId.toString());
        }
        map.put("storeId", storeId);
        map.put("beginTime", request.getParameter("beginTime"));
        map.put("endTime", request.getParameter("endTime"));
        map.put("jobType", "STOCK_TO_PLATFORM_PRODUCT");
        return service.getListPage(map);
    }

}

